package com.zyh.day05.operator

import org.apache.spark.sql.functions.{col, lit}
import org.apache.spark.sql.{DataFrame, SparkSession}

object LitTest {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder()
      .master("local[*]")
      .appName("lt")
      .getOrCreate()

    val list = List((1, "xiaohei", 18, "F",1000.0), (2, "xiao2hei", 18, "F",2000.0), (3, "xiao3hei", 20, "M",3000.0), (4, "xiao4hei", 22, "M",4000.0))

    import spark.implicits._
    val df: DataFrame = list.toDF("id", "name", "age", "sex","salary")

    //val result: DataFrame = df.select(col("id"), col("name"), col("salary"),lit("12").as("月份"))
    //val result: DataFrame = df.select(col("*"), (col("salary") * 12).as("年薪"))
    val result: DataFrame = df.withColumn("年薪", col("salary") * 12)

    result.show()
    spark.close()

  }
}
